<template>
  <vx-card no-shadow>

    <vs-input class="w-full mb-base" label-placeholder="旧密码" v-model="old_password" />
    <vs-input class="w-full mb-base" label-placeholder="新密码" v-model="new_password" />
    <vs-input class="w-full mb-base" label-placeholder="确认密码" v-model="confirm_new_password" />

    <!-- Save & Reset Button -->
    <div class="flex flex-wrap items-center justify-end">
      <vs-button class="ml-auto mt-2" @click="savechanges">Save Changes</vs-button>
      <!--vs-button class="ml-4 mt-2" type="border" color="warning">Reset</vs-button-->
    </div>
  </vx-card>
</template>

<script>
export default {
  data () {
    return {
      old_password: '',
      new_password: '',
      confirm_new_password: ''
    }
  },
  computed: {

  },
  watch:{
    isSidebarActive(val) {
      if (!val) return;
      console.log(this.data);
      if(Object.entries(this.data).length === 0){
        this.initValues();
      }else{
        const { old_password, new_password,confirm_new_password} = JSON.parse(JSON.stringify(this.data));
        this.dataId = id;
        this.old_password   = old_password;
        this.new_password = new_password;
        this.confirm_new_password = confirm_new_password;
      }
    },


  },
  methods: {
    initValues() {
      if (this.data.id) return;
        this.dataId = '';
        this.old_password   = '';
        this.new_password = '';
        this.confirm_new_password = '';
      },
        savechanges() {
        let _this = this;
        const info = {
        old_password:_this.old_password,
        new_password:_this.new_password,
        confirm_new_password:_this.confirm_new_password,
        };
          _this.$axios({
              url: "/admin/Login/eitpassword",
              method: "post",
              data:info,
          }).then((res) => {
              if(res.data.status == 1){
                  _this.$vs.notify({
                  title: '提示',
                  text: res.data.msg,
                  iconPack: 'feather',
                  icon: 'icon-alert-circle',
                  color: 'success'
                  })
                  this.$emit("closeSidebar");
                  this.$emit("reload");
                  this.initValues();
              }else{
                  _this.$vs.notify({
                  title: '提示',
                  text: res.data.msg,
                  iconPack: 'feather',
                  icon: 'icon-alert-circle',
                  color: 'danger'
                  })
              }
          });
      },
      
  },
  mounted(){
    this.savechanges();
  }
}
</script>
